<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <el-form
        :model="where"
        label-width="77px"
        class="ele-form-search"
        @keyup.enter.native="reload"
        @submit.native.prevent>
        <el-row :gutter="15">
<el-col :lg="6" :md="12">
             <el-form-item label="统计学年:">
               <el-select
                 filterable
                 clearable
                 v-model="where.annual"
                 @change="$forceUpdate()"
                 size="small"
                 placeholder="-学年统计-"
                 class="ele-block">
                 <el-option v-for="item in xuenianList" :key="item.id" :label="item.name" :value="item.id"/>
               </el-select>
             </el-form-item>
           </el-col>
           <el-col :lg="10" :md="12">
             <el-form-item label="统计日期:">
               <el-col :lg="8" :md="12">
                 <el-date-picker
                   type="date"
                   class="ele-fluid"
                   v-model="where.startTime"
                   value-format="yyyy-MM-dd"
                   format="yyyy-MM-dd"
                   placeholder="请选择开始日期"/>
               </el-col>
               <el-col :lg="2" :md="12">
                 至
               </el-col>
               <el-col :lg="8" :md="12">
                 <el-date-picker
                   type="date"
                   class="ele-fluid"
                   v-model="where.endTime"
                   value-format="yyyy-MM-dd"
                   format="yyyy-MM-dd"
                   placeholder="请选择结束日期"/>
               </el-col>
             </el-form-item>
           </el-col>
          <el-col :lg="6" :md="12">
            <el-form-item label="项目:">
              <el-select
                filterable
                clearable
                v-model="where.projectId"
                @change="$forceUpdate()"
                size="small"
                placeholder="-运动项目-"
                class="ele-block">
                <el-option v-for="item in projectList" :key="item.id" :label="item.name" :value="item.id"/>
              </el-select>
            </el-form-item>
          </el-col>
           <el-col :lg="6" :md="12">
             <el-form-item ref="class" prop="class" label="年级:">
               <el-select
                 filterable
                 clearable
                 v-model="where.gradeId"
                 @change="$forceUpdate()"
                 size="small"
                 placeholder="-请选择年级-"
                 class="ele-block">
                 <el-option v-for="item in gradeList" :key="item.id" :label="item.name" :value="item.id"/>
               </el-select>
             </el-form-item>
           </el-col>
                        <el-col :lg="6" :md="12">
            <div class="ele-form-actions">
              <el-button
                type="primary"
                icon="el-icon-search"
                class="ele-btn-icon"
                @click="reload">查询
              </el-button>
              <el-button @click="reset">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :where="where"
        :datasource="url"
        :columns="columns"
        :selection.sync="selection"
        height="calc(100vh - 315px)">
        <!-- 表头工具栏 -->
        <template slot="toolbar">
          <el-button
            size="small"
            type="primary"
            icon="el-icon-plus"
            class="ele-btn-icon"
            @click="openEdit(null)"
            v-if="permission.includes('sys:match:add')">添加
          </el-button>
          <el-button
            size="small"
            type="danger"
            icon="el-icon-delete"
            class="ele-btn-icon"
            @click="removeBatch"
            v-if="permission.includes('sys:match:dall')">删除
          </el-button>
        </template>
        <!-- 操作列 -->
        <template slot="action" slot-scope="{row}">
            <el-link
		        type="primary"
		        :underline="false"
		        icon="el-icon-view"
		        @click="openSaishiBaobiao(row)"
		        v-if="permission.includes('sys:match:edit')">赛事报表
            </el-link>
          <el-link
            type="primary"
            :underline="false"
            icon="el-icon-view"
            @click="openRank(row)"
            v-if="permission.includes('sys:match:edit')">排名
          </el-link>
          <el-link
            type="primary"
            :underline="false"
            icon="el-icon-edit"
            @click="openEdit(row)"
            v-if="permission.includes('sys:match:edit')">修改
          </el-link>
          <el-popconfirm
            class="ele-action"
            title="确定要删除此赛事列吗？"
            @confirm="remove(row)">
            <el-link
              type="danger"
              slot="reference"
              :underline="false"
              icon="el-icon-delete"
              v-if="permission.includes('sys:match:delete')">删除
            </el-link>
          </el-popconfirm>
        </template>
                            <!-- 封面列 -->
          <template slot="avatar" slot-scope="{row}">
            <el-avatar shape="square" :size="25" :src="row.avatar"/>
          </template>









                        </ele-pro-table>
    </el-card>
    <!-- 排名弹窗 -->
    <record
      :data="current"
      :visible.sync="showRank"/>
    <!-- 编辑弹窗 -->
    <match-edit
      :data="current"
      :visible.sync="showEdit"
      @done="reload"/>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import Record from './record';
import MatchEdit from './match-edit';

export default {
  name: 'ExamMatch',
  components: {Record,MatchEdit},
  computed: {
    ...mapGetters(["permission"]),
  },
  data() {
    return {
      // 表格数据接口
      url: '/match/index?mtype=1',
      // 表格列配置
      columns: [
        {
          columnKey: 'selection',
          type: 'selection',
          width: 45,
          align: 'center',
          fixed: "left"
        },
        {
          prop: 'id',
          label: 'ID',
          width: 60,
          align: 'center',
          showOverflowTooltip: true,
          fixed: "left"
        },
        {
          prop: 'pro_name',
          label: '项目',
          showOverflowTooltip: true,
          minWidth: 200,
          align: 'center',
        },
        {
          prop: 'grade_name',
          label: '年级',
          showOverflowTooltip: true,
          minWidth: 200,
          align: 'center',
        },
              {
          columnKey: 'avatar',
          label: '封面',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 100,
          slot: 'avatar'
        },
                    {
          prop: 'name',
          label: '赛事名称',
          showOverflowTooltip: true,
          minWidth: 200,
          align: 'center',
        },
        {
          prop: 'begin_time',
          label: '开始时间',
          showOverflowTooltip: true,
          minWidth: 200,
          align: 'center',

        },
                    {
          prop: 'end_time',
          label: '结束日期',
          showOverflowTooltip: true,
          minWidth: 200,
          align: 'center',

        },
        {
          prop: 'match_status',
          label: '赛事状态',
          showOverflowTooltip: true,
          minWidth: 200,
          align: 'center',
        },
        {
          columnKey: 'action',
          label: '操作',
          width: 200,
          align: 'center',
          resizable: false,
          slot: 'action',
          fixed: "right"
        }
      ],
      // 表格搜索条件
      where: {},
      // 表格选中数据
      selection: [],
      // 当前编辑数据
      current: null,
      // 是否显示排名弹窗
      showRank: false,
      // 是否显示编辑弹窗
      showEdit: false,
      projectList:[],
      xuenianList:[],
      gradeList: [],
      departmentsList:[],
    };
  },
  mounted() {
    // 获取项目
    this.getProjectList();
    // 获取学年
    this.getXueList();
    // 获取班级列表
    //this.getClassList();
    this.getGradeList();
  },
  methods: {
    /* 刷新表格 */
    reload() {
      this.$refs.table.reload({where: this.where});
    },
    /* 重置搜索 */
    reset() {
      this.where = {};
      this.reload();
    },
    /* 显示排名 */
    openRank(row) {
      this.current = row;
      this.showRank = true;
    },
	  openSaishiBaobiao(row){
		  this.$router.push({path: '/saishiAnalysis', query: {name: row.name,id:row.id,type:3}});
	  },
    /* 显示编辑 */
    openEdit(row) {
      this.current = row;
      this.showEdit = true;
    },
    /**
     * 获取组织列表
     */
    getGradeList() {
      this.$http.get('/grade/getGradeList').then(res => {
        if (res.data.code === 0) {
          this.gradeList = res.data.data;
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        this.$message.error(e.message);
      });
    },
    /**
      * 获取院系列表
      */
      getDepartmentsList() {
       this.$http.post('/departments/getDepartmentsList').then(res => {
          if (res.data.code === 0) {
            this.departmentsList = res.data.data;
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          this.$message.error(e.message);
        });
    },
    /**
        * 获取组织列表
        */
       getProjectList() {
         this.$http.get('/project/getProjectList').then(res => {
           if (res.data.code === 0) {
             this.projectList = res.data.data;
           } else {
             this.$message.error(res.data.msg);
           }
         }).catch(e => {
           this.$message.error(e.message);
         });
       },
       getXueList() {
         this.$http.get('/annual/getXueList').then(res => {
           if (res.data.code === 0) {
             this.xuenianList = res.data.data;
           } else {
             this.$message.error(res.data.msg);
           }
         }).catch(e => {
           this.$message.error(e.message);
         });
       },
    /**
        * 获取班级列表
        */
       getClassList() {
         if(this.where.superior){
           this.where.class = null;
           this.$forceUpdate();
         }
         this.$http.post('/clss/getClassList',{yid:this.where.superior}).then(res => {
           if (res.data.code === 0) {
             this.classList = res.data.data;
           } else {
             this.$message.error(res.data.msg);
           }
         }).catch(e => {
           this.$message.error(e.message);
         });
       },
    /* 删除 */
    remove(row) {
      const loading = this.$loading({lock: true});
      this.$http.post('/match/delete', {id: row.id}).then(res => {
        loading.close();
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
          this.reload();
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        loading.close();
        this.$message.error(e.message);
      });
    },
    /* 批量删除 */
    removeBatch() {
      if (!this.selection.length) {
        this.$message.error('请至少选择一条数据');
        return;
      }
      this.$confirm('确定要删除选中的赛事列吗?', '提示', {
        type: 'warning'
      }).then(() => {
        const loading = this.$loading({lock: true});
        this.$http.post('/match/delete', {id: this.selection.map(d => d.id)}).then(res => {
          loading.close();
          if (res.data.code === 0) {
            this.$message.success(res.data.msg);
            this.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          loading.close();
          this.$message.error(e.message);
        });
      }).catch(() => {
      });
    },
                                                                }
}
</script>

<style scoped>
</style>
